/**
 * 各种推送方法
 * @author yangxiao
 * @module util/get-send-function
 */

import * as ws from 'ws';
import * as log from '../lib/log/log'


/**
 * 
 *  推送消息到指定客户端
 * @export
 * @param {*} data 要推送的数据 protobuf
 * @param {ws} client 要推送到的客户端
 * @param {string} filename 当前的文件名
 */
export function send(data:any,client:ws,filename:string,isLog=true){
    if(client==null){
        log.getLogger(log.type.rpcLog).error("client==null",filename,data.getMsgCode(),data.toBase64());
        return
    }
    client.send(data.toArrayBuffer(),{mask:true,binary:true},(err)=>{
        if(err)
            log.getLogger(log.type.rpcLog).error(err,filename,data.getMsgCode(),data.toBase64());
    });
}